echo "Change hostname!"
echo " "
echo "Will change password for root..."
echo " "
echo "Will change hostname on CentOS machine... to the first argument"
echo ""
echo " ALSO.... as a bonus... bill do yum update and yum upgrade"

IPAddr=`ifconfig eth0 | awk '/inet addr/{print substr($2,6)}'`

NewFQDN="${1}"
NewHostname=`echo ${NewFQDN} | cut -d"." -f1 `

CurrentHostname=`hostname`

NetFilename="/etc/sysconfig/network"
HostFilename="/etc/hosts"


echo "IP Address      = ${IPAddr}"
echo "NewFQDN         = ${NewFQDN}"
echo "NewHostname     = ${NewHostname}"
echo "CurrentHostname = ${CurrentHostname}"
echo "NetFilename     = ${NetFilename}"
echo "HostFilename    = ${HostFilename}"

if [ "${CurrentHostname}" != "localhost.localdomain" ]
then
        echo "Hey man, are you sure?  hostname is not localhost.localdomain."
        exit 1
fi


if [  "${NewHostname}" = "" ]
then
        echo "First argument must be hostname!"
else
        echo "Will change hostname to ${NewHostname}"
        echo " "
        echo "Change password..."
        passwd
        echo " "
        echo "Change hostname to ${NewHostname}"

        echo "1. Changing ${NetFilename}!"
        sed -i  "s/HOSTNAME.*/HOSTNAME=${NewFQDN}/g" ${NetFilename}
        echo "New file is:"
        cat ${NetFilename}

        echo "2. Changing ${HostFilename}!"
        echo "${IPAddr} ${NewFQDN}      ${NewHostname}" >> ${HostFilename}

        echo "New Host Filename is:"
        cat ${HostFilename}

        echo "Don't forget to reboot!"
fi



echo "Yum Update... will be quiet about it, so stand by for awhile..."
yum -y -q update

echo "Yum Upgrade... will be quiet about it, so stand by for awhile..."
yum -y -q upgrade

yum clean

